<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <title>Unicode转中文、中文Unicode编码、ASCII转Unicode、Unicode转ASCII - 在线工具 - DevTools</title>
    <meta name="keywords" content="Unicode转中文,中文转Unicode,ASCII转Unicode,Unicode转ASCII">
    <meta name="description" content="在线Unicode编码转换工具,Unicode转中文,中文转Unicode,ASCII转Unicode,Unicode转ASCII">
    <link rel="shortcut icon" href="/favicon.ico">
    <link href="https://cdn.bootcss.com/font-awesome/5.10.0-11/css/all.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/static/css/style.css" type="text/css">
</head>
<body>
{{template "aside"}}
<main>
    <div class="container">
        <h1>新片场下载链接获取</h1>
        <textarea id="area_input" class="textarea mt-2" rows="15"></textarea>
        <div id="btns" class="content-center mt-2">
            <button class="button" onclick="decodeUnicode()">
                <i class="fa fa-arrow-down"></i>
                <span>获取下载链接并下载</span>
            </button>
            <button class="button" onclick="cleanup()">清空</button>
        </div>
        <textarea id="area_output" class="textarea mt-2" rows="15"></textarea>
    </div>
</main>
<script>
    let area_input = document.getElementById('area_input');
    let area_output = document.getElementById('area_output');

    function decodeUnicode() {
        let input = area_input.value;
        area_output.value = unescape(input.replace(/\\u/gi, '%u'));
        selectBtn(0)
    }

    function encodeUnicode() {
        let input = area_input.value;
        let res = [];
        for (let i = 0; i < input.length; i++) {
            res[i] = ("00" + input.charCodeAt(i).toString(16)).slice(-4);
        }
        area_output.value = "\\u" + res.join("\\u");
        selectBtn(1)
    }

    function asciiToUnicode() {
        let input = area_input.value;
        let code = input.match(/&#(\d+);/g);
        let result = '';
        if (code === null) {
            area_output.value = '';
            return
        }
        for (let i = 0; i < code.length; i++) {
            result += String.fromCharCode(code[i].replace(/[&#;]/g, ''));
        }
        area_output.value = result;
        selectBtn(2)
    }

    function unicodeToAscii() {
        let input = area_input.value;
        let result = '';
        for (let i = 0; i < input.length; i++) {
            result += '&#' + input.charCodeAt(i) + ';';
        }
        area_output.value = result;
        selectBtn(3)
    }

    function selectBtn(index) {
        let btns = document.querySelectorAll('#btns button');
        for (let i = 0; i < btns.length; i++) {
            if (i === index) {
                btns[i].classList.add('primary')
            } else {
                btns[i].classList.remove('primary')
            }
        }
    }

    function cleanup() {
        area_input.value = '';
        area_output.value = '';
        selectBtn(-1)
    }
</script>
</body>
</html>